package core.impl.p3;

import api.a1.KieSessionMonitoringMXBean;
import api.kiecontainer.KieRuntimeEventManager;
import api.kiecontainer.KieSessionModel;
import core.api.a3.InternalWorkingMemoryActions;

import javax.management.ObjectName;

public class KieSessionMonitoringImpl extends GenericKieSessionMonitoringImpl implements KieSessionMonitoringMXBean {
    
    private ObjectName name;

    public KieSessionMonitoringImpl(String containerId, String kbaseId, String ksessionName) {
        super(containerId, kbaseId, ksessionName);
        
        this.name = DroolsManagementAgent.createObjectNameBy(containerId, kbaseId, KieSessionModel.KieSessionType.STATEFUL, ksessionName);
    }
    
    @Override
    public ObjectName getName() {
        return this.name;
    }

    @Override
    public long getTotalSessions() {
        return ksessions.size();
    }

    @Override
    public long getTotalFactCount() {
        long result = 0;
        for (KieRuntimeEventManager s : ksessions) {
            result += ((InternalWorkingMemoryActions) s).getFactCount();
        }
        return result;
    }
}
